﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

using PdfCreative.Pdf.Writer;

namespace PdfCreative.Pdf.Graphics
{
    /// <summary>
    /// The RgbColour represents a colour that uses the RGB colour space. The colour is composed of
    /// three components; red, green; and blue.
    /// </summary>
    public class RgbColour : Colour
    {        
        // Base class overrides
        // ====================
        #region Colour overrides
        /// <summary>
        /// Clones the CmykColour instance.
        /// </summary>
        /// <returns>The clone.</returns>
        public override Colour Clone()
        {
            return new RgbColour(
                _components[0],
                _components[1],
                _components[2]);
        }

        /// <summary>
        /// Retrieves the number of components in this colour.
        /// </summary>
        /// <returns></returns>
        protected override int GetComponentLength()
        {
            return 3;
        }

        /// <summary>
        /// Writes an instruction to set the current non-stroking colour.
        /// </summary>
        /// <param name="writer">The PDF writer to use.</param>
        protected internal override void WriteNonStrokeColour(PdfWriter writer)
        {
            writer.SetNonStrokeColour(this.Red, this.Green, this.Blue);
        }

        /// <summary>
        /// Writes an instruction to set the current stroking colour.
        /// </summary>
        /// <param name="writer">The PDF writer to use.</param>
        protected internal override void WriteStrokeColour(PdfWriter writer)
        {
            writer.SetStrokeColour(this.Red, this.Green, this.Blue);
        }
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Sets or retrieves the blue component of the colour.
        /// </summary>
        public byte Blue
        {
            get { return _components[2]; }
            set { _components[2] = value; }
        }

        /// <summary>
        /// Sets or retrieves the green component of the colour.
        /// </summary>
        public byte Green
        {
            get { return _components[1]; }
            set { _components[1] = value; }
        }

        /// <summary>
        /// Sets or retrieves the red component of the colour.
        /// </summary>
        public byte Red
        {
            get { return _components[0]; }
            set { _components[0] = value; }
        }
        #endregion



        // Public constructor
        // ==================
        #region Public constructor
        /// <summary>
        /// Constructs a new RgbColour instance.
        /// </summary>
        /// <param name="red"></param>
        /// <param name="green"></param>
        /// <param name="blue"></param>
        public RgbColour(int red, int green, int blue)
            : base()
        {
            _colourSpace = ColourSpace.DeviceRGB;
            this.Red = (byte)red;
            this.Green = (byte)green;
            this.Blue = (byte)blue;
        }
        #endregion

    } // RgbColour class
}
